#include <iostream>

int divide(int a, int b)
{
    if (b == 0)
        throw "char error!";
    if (b == 1)
        throw -1;
    if (b == 2)
        throw 3.14;
    if (b == 3)
        throw &a;
    return 0;
}

int main()
{
    try
    {
        // int c = divide(9,0);
        // int c = divide(9,1);
        // int c = divide(9,2);
        int c = divide(9, 3);
    }
    // 捕获某种数据类型的异常 : 严格匹配
    catch (const char *s)
    {
        std::cout << "捕获到字符串异常:" << s << std::endl;
    }
    // 多分支捕获异常
    catch (int a)
    {
        std::cout << "捕获到整型异常:" << a << std::endl;
    }
    catch (double a)
    {
        std::cout << "捕获到浮点型异常:" << a << std::endl;
    }
    catch (...) // 捕获其他类型的异常
    {
        std::cout << "捕获到其他类型异常" << std::endl;
    }
    return 0;
}